package com.anhdt.dao;

import com.anhdt.vo.TopicVO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TopicDAO extends BaseDAO{

   private static TopicDAO topicDAO;
   
   private TopicDAO(){
   }
   
   public static TopicDAO getInstance() {
        if (topicDAO == null) {
            topicDAO = new TopicDAO();
        }
        return topicDAO;
    }

    public List<TopicVO> getAllTopic() throws SQLException {
        List<TopicVO> list = new ArrayList<>();
        String sql = "Select * from cate_parrent order by id";
       try (Connection conn = connect.getConnnection()) {
           PreparedStatement stmt = conn.prepareStatement(sql);
            try (ResultSet res = stmt.executeQuery()) {
                while (res.next()) {
                    TopicVO tmp = new TopicVO();
                    int id = res.getInt("id");
                    String name = res.getString("name");
                    tmp.setId(id);
                    tmp.setName(name);
                    list.add(tmp);
                }}
            stmt.close();
       }
       
       return list;
    }
}
